function getJSON(url, useJSON = true) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest()
    xhr.open('GET', url)
    if (useJSON) {
      xhr.responseType = 'json'
      xhr.setRequestHeader('Accept', 'application/json')
    }
    xhr.send()
    xhr.onreadystatechange = () => {
      if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
          resolve(xhr.response)
        } else {
          reject(new Error(xhr.statusText))
        }
      }
    }
  })
}
